import destroy from '../destroy.coffee'

export default (action)=>
  BrowserWindow.getAllWindows().forEach(
    (w)=>
      url = w.webContents.getURL()
      if url
        {hash} = new URL url
        hash = hash[1..]
        if hash.startsWith 'main'
          if action
            w[action]()
            if action == 'show'
              w.once 'show',=>
                w.setAlwaysOnTop(true,'screen-saver')
                setTimeout(
                  =>
                    w.setAlwaysOnTop(false,'screen-saver')
                  1000
                )
                return
          else
            w.hide()
          return
        if hash.startsWith 'camera'
          #w.setVisibleOnAllWorkspaces(false, { visibleOnFullScreen: false })
          return
      destroy w
      return
  )
  return

export x = =>
  BrowserWindow.getAllWindows().forEach(
    (w)=>
      url = w.webContents.getURL()
      if url
        {hash} = new URL url
        hash = hash[1..]
        if hash.startsWith 'main'
          w.hide()
          return
      destroy w
      return
  )
  return
